package cn.iocoder.yudao.module.blog.service.jiucaselevel;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.blog.controller.admin.jiucaselevel.vo.*;
import cn.iocoder.yudao.module.blog.dal.dataobject.jiucaselevel.BlogJiuCaseLevelDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.blog.convert.jiucaselevel.BlogJiuCaseLevelConvert;
import cn.iocoder.yudao.module.blog.dal.mysql.jiucaselevel.BlogJiuCaseLevelMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.blog.enums.ErrorCodeConstants.*;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;

/**
 * 灸法案例审批等级 Service 实现类
 *
 * @author 曹建伟
 */
@Service
@Validated
public class BlogJiuCaseLevelServiceImpl implements BlogJiuCaseLevelService {

    @Resource
    private BlogJiuCaseLevelMapper jiuCaseLevelMapper;

    @Override
    public Long createJiuCaseLevel(BlogJiuCaseLevelCreateReqVO createReqVO) {
        // 插入
        BlogJiuCaseLevelDO jiuCaseLevel = BlogJiuCaseLevelConvert.INSTANCE.convert(createReqVO);
        jiuCaseLevelMapper.insert(jiuCaseLevel);
        // 返回
        return jiuCaseLevel.getId();
    }

    @Override
    public void updateJiuCaseLevel(BlogJiuCaseLevelUpdateReqVO updateReqVO) {
        // 校验存在
        validateJiuCaseLevelExists(updateReqVO.getId());
        // 更新
        BlogJiuCaseLevelDO updateObj = BlogJiuCaseLevelConvert.INSTANCE.convert(updateReqVO);
        jiuCaseLevelMapper.updateById(updateObj);
    }

    @Override
    public void deleteJiuCaseLevel(Long id) {
        // 校验存在
        validateJiuCaseLevelExists(id);
        // 删除
        jiuCaseLevelMapper.deleteById(id);
    }

    private void validateJiuCaseLevelExists(Long id) {
        if (jiuCaseLevelMapper.selectById(id) == null) {
            throw exception(JIU_CASE_LEVEL_NOT_EXISTS);
        }
    }

    @Override
    public BlogJiuCaseLevelDO getJiuCaseLevel(Long id) {
        return jiuCaseLevelMapper.selectById(id);
    }

    @Override
    public List<BlogJiuCaseLevelDO> getJiuCaseLevelList(Collection<Long> ids) {
        if (CollUtil.isEmpty(ids)) {
            return ListUtil.empty();
        }
        return jiuCaseLevelMapper.selectBatchIds(ids);
    }

    @Override
    public List<BlogJiuCaseLevelDO> getAll(){
        return jiuCaseLevelMapper.selectList();
    }

    @Override
    public PageResult<BlogJiuCaseLevelDO> getJiuCaseLevelPage(BlogJiuCaseLevelPageReqVO pageReqVO) {
        return jiuCaseLevelMapper.selectPage(pageReqVO);
    }

    @Override
    public List<BlogJiuCaseLevelDO> getJiuCaseLevelList(BlogJiuCaseLevelExportReqVO exportReqVO) {
        return jiuCaseLevelMapper.selectList(exportReqVO);
    }

}
